package com.example.demo.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.example.demo.pojo.Album;
import com.example.demo.pojo.User;
import com.example.demo.service.AlbumService;

@Controller
@RequestMapping("/album")
public class AlbumAction {
	
	
	@Autowired
	private AlbumService albumService;
	
	@RequestMapping("/getAlbumList")
	public String getAlbumList(Model model) {
		List<Album> getlist=albumService.getAlbumList();
		model.addAttribute("getlist", getlist);
		return "/user/ht_album";
	}
	
	@RequestMapping("/getList")
	public String getList(Model model,int album_id) {
		Album album=albumService.getList(album_id);
		model.addAttribute("album",album);
		return "xiugaialbumxx";
	}
	@RequestMapping("/updateAlbum")
	public String updateAlbum(Model model,Album album) {
		boolean f=albumService.updateAlbum(album);
		if(f) {
			return "forward:/album/getAlbumList";
		}
		else {
			model.addAttribute("result","no");
			model.addAttribute("msg","对不起，修改失败！");
			return "/user/result";	
		}
	}
	
	@RequestMapping("/searchAlbumList")
	public String searchMvList(Model model,String album_name) {
		List<Album> getlist=albumService.searchAlbumList(album_name);
		model.addAttribute("getlist",getlist);
		return "/user/ht_album";
	}
	@RequestMapping("/addAlbum")
	public String addAlbum(Album album,Model model) {
		int i=albumService.addAlbum(album);
		if(i==0) {
			model.addAttribute("result","yes");
			model.addAttribute("msg","恭喜您，注册成功！");
		}else if(i==1) {
			model.addAttribute("result","no");
			model.addAttribute("msg","恭喜您，该用户也注册，请更换！");
		}else if(i==2) {
			model.addAttribute("result","no");
			model.addAttribute("msg","对不起，注册失败！");
		}
		return"forward:/album/getAlbumList";
	}
	@RequestMapping("/deleteAlbum")
	public String deleteAlbum(Album album,Model model) {
		boolean f=albumService.deleteAlbum(album);
		if(f) {
			return "forward:/album/getAlbumList";
		}
		else {
			model.addAttribute("result","no");
			model.addAttribute("msg","删除失败");
			return "/user/result";	
		}
	}
}
